//
// Created by 吴喆 on 2020/4/8.
//

#include "FontAtlas.h"

FontAtlas::FontAtlas(Font *font) : font(font) {
}

FontAtlas::~FontAtlas() {
    delete font;
    for (auto ch : characters) {
        delete ch.second;
    }
}

Character *FontAtlas::find(wchar_t ch) {

    Character *character;
    if (characters.find(ch) != characters.end()) {
        character = characters.at(ch);
        if (character == nullptr) {
            characters.insert(std::pair(ch, character = font->initCharacter(ch)));
        }
    } else {
        characters.insert(std::pair(ch, character = font->initCharacter(ch)));

    }
    return character;
}
